function [fullfile filetext messages] = jcb_pick_next_lsf(oldfiletext)
%JCB_PICK_NEXT_LSF will return, as a string, the next lsf file to be run by
%   fdtd.
    messages='';
    if ~strcmp(oldfiletext,fileread(jcb_lsf_list()));
        % file text has changed - do something?
        messages = [messages 'the text of the list file, ' ...
            jcb_lsf_list() ' has changed. re-reading the list.'];
        filetext = fileread(jcb_lsf_list());
    else
        messages = [messages 'the text of the list file, ' ...
            jcb_lsf_list() ' has not changed.'];
        filetext = oldfiletext;
    end
    
    % split filetext into lines & place in cell array
    [s e] = regexp(filetext,'[^\r\n]*','start','end');
    filenames = cell(length(s),1);
    filepaths = cell(length(s),1);
    for ii=1:length(s)
        [filepaths{ii} filenames{ii}] = ...
            fileparts(strtrim(filetext(s(ii):e(ii))));
        if strcmp(filepaths{ii},'') 
            if ii==1
                filepaths{ii} = pwd;
            else
                filepaths{ii} = filepaths{ii-1};
            end
        end
    end
    fullfile = '';
    return
end